local tianyin = fk.CreateSkill {
  name = "mini__tianyin",
}

Fk:loadTranslationTable{
  ["mini__tianyin"] = "天音",
  [":mini__tianyin"] = "结束阶段，你从牌堆中获得你本回合未使用过类型的牌各一张，若你未因此获得牌，你可以弃置一名其他角色一张牌。",

  ["#mini__tianyin-choose"] = "天音：你可以弃置一名其他角色一张牌",

  ["$mini__tianyin1"] = "吟猱观抑按，百鸟来和鸣。",
  ["$mini__tianyin2"] = "情舒放而远览，接轩辕之遗音。",
}

tianyin:addEffect(fk.EventPhaseStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(tianyin.name) and player.phase == Player.Finish
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local types = {"basic", "trick", "equip"}
    room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
      local use = e.data
      if use.from == player then
        table.removeOne(types, use.card:getTypeString())
      end
    end, Player.HistoryTurn)
    local cards = {}
    for _, type in ipairs(types) do
      local card = room:getCardsFromPileByRule(".|.|.|.|.|"..type)
      if #card > 0 then
        table.insert(cards, card[1])
      end
    end
    if #cards > 0 then
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, tianyin.name, nil, false, player)
    else
      local targets = table.filter(room:getOtherPlayers(player, false), function(p)
        return not p:isNude()
      end)
      local to = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets = targets,
        skill_name = tianyin.name,
        prompt = "#mini__tianyin-choose",
        cancelable = true,
      })
      if #to > 0 then
        to = to[1]
        local id = room:askToChooseCard(player, {
          target = to,
          flag = "he",
          skill_name = tianyin.name,
        })
        room:throwCard(id, tianyin.name, to, player)
      end
    end
  end,
})

return tianyin
